package org.grottarossa.ui.core.components;

import java.util.HashMap;
import java.util.ResourceBundle;

import org.grottarossa.template.data.pojo.query.Query;
import org.grottarossa.template.drivers.DriverException;
import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.base.BasePanel;
import org.grottarossa.ui.core.components.tables.TMSFilteredTable;
import org.grottarossa.ui.core.i18n.DM;



import com.vaadin.Application;
import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window.Notification;
import com.vaadin.ui.Label;

/***
 * Pannello con la tabella delle query
 * @author Administrator
 *
 */
public class TablePanel extends BasePanel
{
	private static final long serialVersionUID = -942154920716455685L;
	private TMSFilteredTable table;
	private Query query;
	Application application;

	private ItemClickListener listener;

	public TablePanel(ApplicationSession appSession, ItemClickListener listener)
	{
		super(appSession, DM.instance().getBundle(TablePanel.class.getName()));
		this.listener = listener;
		initializeComponents();
	}

	@Override
	protected void initializeComponents()
	{
	}

	public void draw(String queryScriptName,HashMap<String, String> params)
	{
		try
		{
			query = m_appSession.getBuilder().getCaseManagement().executeQuery(queryScriptName, params);

			table = new TMSFilteredTable(m_appSession, query);
			table.addListener(listener);
			table.setSizeFull();

			VerticalLayout layout = new VerticalLayout();
			layout.setSizeFull();
			layout.addComponent(table);
			this.setContent(layout);
		}
		catch (DriverException e)
		{
			showError(e);
		}
	}
}